package com.boolib.animate.commons.exception;

import com.alibaba.fastjson.JSON;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author nier
 * @create 2020-02-16 14:06
 */
@Component
@Slf4j
public class ExceptionIntercep extends HandlerInterceptorAdapter {


    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {






    }


    @SneakyThrows
    private void responseWrite(HttpServletResponse res, MyGlobalExceptionHandler.ErrorResult resultVo)  {
        res.setHeader("Access-Control-Allow-Origin", "*");
        res.setCharacterEncoding("utf-8");
        res.setContentType("application/json; charset=utf-8");
        PrintWriter writer = res.getWriter();
        writer.write(JSON.toJSONString(resultVo));
    }
}

